package com.jeremyfeinstein.utils;

import android.os.Handler;
import android.os.HandlerThread;

/**
 * Created by sunxunchao on 2018/12/4.
 */
public class SwitchToIOThread {
    private static SwitchToIOThread instance;
    private Handler mHandler;
    private HandlerThread handlerThread;

    public static SwitchToIOThread getInstance(){
      //  if (instance == null){
          //  synchronized (SwitchToMainThread.class){
                if (instance == null){
                    instance = new SwitchToIOThread();
                }
           // }
       // }
        return instance;
    }

    private SwitchToIOThread() {
        handlerThread = new HandlerThread("m_io");
        handlerThread.start();
        mHandler = new Handler(handlerThread.getLooper());
    }

    public void post(Runnable runnable){
        mHandler.post(runnable);
    }


    public void postDelayed(Runnable runnable, long delayMillis){
        mHandler.postDelayed(runnable, delayMillis);
    }
}
